'use strict';
module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;
  const Content = app.model.define(
      'Content',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
        user_id: INTEGER,
        title: STRING(255),
        desc: TEXT,
        image: TEXT,
        create_by: STRING(255),
      },
      {
          tableName: 'content',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
  Content.associate = function() {
    // 关联评论表、点赞表
    app.model.Content.hasMany(app.model.Comment, { foreignKey: 'content_id', targetKey: 'id', as: 'commentList' });
    app.model.Content.hasMany(app.model.Like, { foreignKey: 'content_id', targetKey: 'id', as: 'likeList' });
    // 关联用户
    app.model.Content.belongsTo(app.model.User, { foreignKey: 'user_id', targetKey: 'id', as: 'userInfo' });
  }
  return Content
};
